< previous page page_677 next page >

Page 677
Be careful not to use the Not operator with any data type other than Booleanespecially when youre using numbers that are something other than True or False values (-1 and 0, respectively). Consider the following code:
9f31265bb40b592b1929e18a47ab28e5.gif
Sub cmdBool_Click ()
   Dim intBool As Integer
   Dim intTemp As Integer


   intBool = True
   Print intBool      ' Prints -1
   Print Not intBool  ' Prints 0

   intTemp = 5
   Print intTemp      ' Prints 5
   Print Not intTemp  ' Prints -6
   If intTemp Then
      Print "intTemp is True"   ' Prints Here
   Else
      Print "intTemp is False"
   End If
End Sub
Notice that the Not operator performs bitwise manipulation. Therefore, manipulating 5 actually makes it -6.
Use vbNullString Instead of an Empty String
The constant vbNullString is much more efficient that setting a string variable equal to an empty string (""):
9f31265bb40b592b1929e18a47ab28e5.gif
strValue = ""
Use the following line of code instead:
9f31265bb40b592b1929e18a47ab28e5.gif
strValue = vbNullString
This is an optimization thats built into the compiler. Therefore, instead of having to reallocate memory for the string, you can use a specific constant to set the memory equal to a null pointer and mark the rest of the memory allocated for the string to unused.

 
< previous page page_677 next page >

If you like this book, buy it!